using Microsoft.SqlServer.Management.Sdk.Sfc;
using System;
using System.IO;

namespace Microsoft.SqlServer.Management.SqlManagerUI.Scripting
{
	internal abstract class TextWriterProvider : IDisposable
	{
		private TextWriter textWriter;

		public abstract TextWriter GetTextWriter(Urn item);

		public virtual void InitializeForUrn(Urn item)
		{
			if (this.textWriter != null)
			{
				throw new InvalidOperationException();
			}
			this.textWriter = this.GetTextWriter(item);
		}

		public virtual void DisposeForUrn()
		{
			if (this.textWriter == null)
			{
				throw new InvalidOperationException();
			}
			this.textWriter.Dispose();
			this.textWriter = null;
		}

		public virtual void WriteLine(string line)
		{
			if (this.textWriter == null)
			{
				throw new InvalidOperationException();
			}
			this.textWriter.WriteLine(line);
		}

		public virtual void Dispose()
		{
		}
	}
}
